package net.ys.controller;

import net.ys.bean.AprApollo;
import net.ys.service.ApiService;
import net.ys.utils.GenResult;
import net.ys.utils.LogUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @author: NMY
 * @Date: 2022/3/15
 * @Time: 11:03
 */
@Controller
@RequestMapping("/api")
public class ApiController {

    @Resource
    private ApiService apiService;

    @GetMapping("/apollo/list")
    @ResponseBody
    public Map<String, Object> listApollo(@RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "10") int pageSize) {
        try {
            if (page < 1) {
                page = 1;
            }
            List<AprApollo> aprApollos = apiService.listApollo(page, pageSize);
            return GenResult.SUCCESS.genResult(aprApollos);
        } catch (Exception e) {
            LogUtil.error(e);
            return GenResult.UNKNOWN_ERROR.genResult();
        }
    }
}
